Skip to content

fix(kimi): gate --work-dir flag on probe, like --print (#1476)#1483

Open
chenhg5 wants to merge 1 commit into
mainfrom
agent/cc-connect/dev-claudecode/t-20260701-ro21vi-1476-kimi-work-dir-gate
Open

fix(kimi): gate --work-dir flag on probe, like --print (#1476)#1483
chenhg5 wants to merge 1 commit into
mainfrom
agent/cc-connect/dev-claudecode/t-20260701-ro21vi-1476-kimi-work-dir-gate

Conversation

@chenhg5

@chenhg5 chenhg5 commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Fixes #1476

问题

Kimi Code CLI builds newer than what #1456 covered dropped the --work-dir
flag. Passing it now produces:

error: unknown option --work-dir

The reporter (#1476, v1.4.1, Kimi Code agent) hits this on every spawn
because session.go:97-99 always appended the flag whenever a non-default
workDir was set. The #1461 / #1456 fix gated --print the same way; this
PR closes the gap for --work-dir.

改动

Follows the exact same probe-based pattern as #1456 / PR #1461 (referenced
for both users and reviewers who already validated that approach).

agent/kimi/probe.go

agent/kimi/session.go

agent/kimi/probe_test.go

  • TestParseKimiHelpFlags_LegacyAdvertisesPrint now also asserts
    flags["--work-dir"] is true (legacy CLI supports it).
  • New constant modernKimiHelpWithoutWorkDir mirrors the Kimi Code CLI
    build the reporter hits (no --print, no --work-dir).
  • New TestParseKimiHelpFlags_ModernWithoutWorkDir asserts neither flag
    is detected on the deeper-no-work-dir surface.
  • Existing TestParseKimiHelpFlags_ModernHidesPrint left intact (it
    covers the in-between surface where --print is gone but --work-dir
    still exists — useful regression coverage).
  • New TestKimiFlagSupport_LegacyHelpSetsWorkDir +
    TestKimiFlagSupport_ModernWithoutWorkDir exercise the full probe-
    mapping, not just parseKimiHelpFlags, since that's what
    buildArgs actually consumes.

agent/kimi/session_test.go

  • TestBuildArgs_WorkDirFlagGatedworkDir=/, flagSupport{WorkDir:false}
    --work-dir MUST NOT appear, AND the value / MUST NOT leak into args
    (catches a partial-gate bug where only the flag name is dropped).
  • TestBuildArgs_WorkDirFlagEmittedworkDir=/, flagSupport{WorkDir:true}
    --work-dir / MUST appear (legacy CLI keeps non-default dir support).

触发条件 / trade-off

  • Why reuse parseKimiHelpFlags instead of adding a new parser?
    --work-dir already appears in the help-text of both legacy and the
    in-between build the existing modernKimiHelp constant models. The
    existing parser picks it up the same way it picked up --print — no
    new parser logic, no new layout assumptions.
  • Why a separate modernKimiHelpWithoutWorkDir instead of editing
    modernKimiHelp?
    The modernKimiHelp constant is anchored in the
    [Bug] ❌ 错误: error: unknown option '--print' (Did you mean --prompt?) #1456 fix history; editing it would silently invalidate that test's
    assertion contract. Two-realistic-surfaces is the cleaner modeling.
  • Risk for users on default dirs? None — cmd.Dir is set
    unconditionally, so whether the CLI sees --work-dir $X or just takes
    cwd from cmd.Dir, the agent runs in the same directory. The only
    practical difference is users on non-default dirs whose modern CLI
    previously crashed: they now get clean startup (cwd fallback).
  • Risk for users with legacy kimi-cli? None — they advertise
    --work-dir in help, the probe sees it, buildArgs still emits it.

验证

  • gofmt -l agent/kimi/ — clean
  • go vet ./agent/kimi/... — clean
  • go test -count=1 ./agent/kimi/... — all pass (4 prior + 6 new =
    10 tests in the probe/session suites)

不做什么

  • 不改 Kimi Code CLI 本身
  • 不改其他 agent adapter (Claude / Codex / Gemini / Cursor / OpenCode
    etc. each have their own flag handling; out of scope)
  • 不改 probe 探测逻辑本身 (沿用现有 kimi --help 解析 + 短超时
    fallback to modern surface on probe failure)
  • 不重构 buildArgs / kimiFlagSupport — 仅加一个 bool 字段

关联

🤖 Generated with Claude Code

Same pattern as the #1456 / PR #1461 --print fix. Newer Kimi Code CLI
builds no longer accept --work-dir, exiting with `error: unknown option
--work-dir` whenever the user's config sets a non-default workspace
directory.

- agent/kimi/probe.go: kimiFlagSupport gains a WorkDir bool; the probe
  fills it from `kimi --help` (parseKimiHelpFlags already scans the
  --work-dir token, no parser changes needed).
- agent/kimi/session.go buildArgs: --work-dir is now emitted only when
  flagSupport.WorkDir is true. The agent still runs in the correct
  directory via exec.Command.Dir (set separately), so omitting the flag
  on modern CLIs is functionally equivalent for users on default dirs
  and graceful for users on non-default dirs whose CLI just ignores it.
- agent/kimi/probe_test.go: extend the legacy test to assert
  --work-dir is detected, add modernKimiHelpWithoutWorkDir constant
  that mirrors the build the reporter hits, plus full
  TestKimiFlagSupport_LegacyHelpSetsWorkDir /
  TestKimiFlagSupport_ModernWithoutWorkDir coverage of the probe mapping.
- agent/kimi/session_test.go: TestBuildArgs_WorkDirFlagGated (no flag
  on modern CLI) + TestBuildArgs_WorkDirFlagEmitted (legacy CLI keeps
  it). Also asserts the work-dir value doesn't leak into args when
  the gate is closed, catching a partial-gate future bug.

go test ./agent/kimi/... — all pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] ❌ 错误: error: unknown option '--work-dir'

1 participant